<?php
include_once "header.php";

$daftar_kewenangan_user = new Daftar_kewenangan_user();
$kewenangan_user = $daftar_kewenangan_user->getAll();

if(isset($_POST['cari_kewenangan_user']) ){
	
	if($_POST['nip']!="") {
	
		$daftar_kewenangan_user = new Daftar_kewenangan_user();
		$kewenangan_user = $daftar_kewenangan_user->getByNip($_POST['nip']);
	}	
}

?>

<div id="container">
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Daftar Kewenangan Pengguna
			</div>
			<div id="body">	
			Kata Kunci: <br/>			
			<form name="form" method="POST" action="daftar_kewenangan_pengguna.php">
			<input type="hidden" name="cari_kewenangan_user">
			<input type="text" name="nip" placeholder="nip" maxlength="18" value="<?php if(isset($_POST['nip'])) echo $_POST['nip']; ?>"> &nbsp &nbsp &nbsp
			<input type="submit" name="submit" value="Submit" onclick="return validasi();">
			<input type="reset" name="reset" value="Reset">
			</form>
			<br/>
			<table id="table2" cellspacing=0 cellpadding=4 width=100%>
				<tr>
					<th>No.</th>
					<th width=25%>Nama / NIP</th>
					<th width=10%>Kewenangan</th>
					<th width=20%>Unit</th>
					<th>Tgl berlaku</th>
					<th>tgl Buat</th>
					<th>Status</th>
					<th></th>
					
				</tr>
				<?php
				$j=1;
				foreach($kewenangan_user as $kewenangan){?>
				
				<tr>
					<td><?php echo $j; ?></td>
					<td>
					<?php 
						$daftar_user = new Daftar_user();
						$user = $daftar_user->getByNip($kewenangan->getNip());
						echo $user->getNama();
						echo "<br/>";
						echo "NIP.".$user->getNip()
					?>
					</td>
					
					<td><?php
					echo $kewenangan->getKewenangan();
					?></td>
					
					<td>
					<?php
						$daftar_unit = new Daftar_unit();
						$unit = $daftar_unit->getById($kewenangan->getUnit());
						echo $unit->getUnit();
					
					?>
					</td>
					
					<td><?php
					echo date('d-m-Y',strtotime($kewenangan->getTgl_mulai()));
					echo " s.d.";
					echo "<br>";
					echo date('d-m-Y',strtotime($kewenangan->getTgl_selesai()));
					?></td>
					
					
					<td>
					<?php 
					echo date('d-m-Y H:i:s',strtotime($kewenangan->getTgl_buat()));
					?>
					</td>
					
					<td>
					<?php 
					if($kewenangan->getTgl_selesai()>=date('Y-m-d')){$status="Aktif";} else {$status="Tidak Aktif";}
					echo $status;
					?>
					</td>
					
					<td><?php 
					
						echo "<a href=\"ubah_kewenangan_pengguna.php?id_kewenangan_user=".$kewenangan->getId()."\" >";
						echo "<img src=\"images/Text-Edit-icon.png\" alt=\"ubah\" title=\"ubah\" width=15px height=15px/></a></a> ";;
						echo "   ";
						
						echo "<a href=\"hapus_kewenangan_pengguna.php?id_kewenangan_user=".$kewenangan->getId()."\" onclick=\"return del()\">";
						echo "<img src=\"images/delete-icon.png\" alt=\"hapus\" title=\"hapus\" width=15px height=15px/></a> ";
						
						
					
					?></td>
					
					
				
				</tr>
				
				<?php $j++;} ?>
			</table>
			<?php
			if(empty($kewenangan)){
				echo "<table cellspacing=0 cellpadding=4 width=100%>";
				echo "<tr>";
				echo "<td>";
					echo "Data tidak tersedia.";	
				echo "</td>";			
				echo "</tr>";
				echo "</table>";
			}
			?>
			<br>
			<input type="button" value="Rekam" onClick="window.location.href='rekam_kewenangan_pengguna.php'">		
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">
	function del(){
	if(confirm('Apakah Anda yakin akan menghapus data ini?'))
	return true;
	else return false
	}
	
	onload=function(){
	
		document.form.onreset=function(){
			window.location="daftar_kewenangan_pengguna.php";
		}
	}
	
	function validasi(){
	var x = document.form.nip.value;
	if (x==""){
		alert('Isikan kata kunci terlebih dahulu!');
		return false;
	}
	}
	
	
	
</script>

